#include "InterviewStack.h"
#include "SeqQueue.h"
#include "SeqStack.h"


#define TEST_HEADER printf("\n********************%s***************\n",__FUNCTION__)


void TestIsStackOrder()
{
    TEST_HEADER;
    char input[]="abcde";
    char output[]="baed";
    int64_t size_in=strlen(input);
    int64_t size_out=strlen(output);
    int ret=0;
    ret=IsStackOrder(input,size_in,output,size_out);
    printf("ret expect 1,actual %d\n",ret);
    puts(input);
    puts(output);
}
void TestMinStack()
{
    TEST_HEADER;
    MinStack minstack;
    MinStackInit(&minstack);
    MinStackType top='\0';
    int ret=0;
    ret=MinStackTop(&minstack,&top);
    printf("尝试对空栈进行取栈顶元素:ret expect 0,actual %d\n",ret);

    MinStackPop(&minstack);
    PrintMinStack(&minstack,"尝试对空栈进行出栈");
    MinStackPush(&minstack,'g');
    MinStackPush(&minstack,'f');
    MinStackPush(&minstack,'e');
    MinStackPush(&minstack,'d');
    MinStackPush(&minstack,'c');
    MinStackPush(&minstack,'b');
    MinStackPush(&minstack,'a');
    PrintMinStack(&minstack,"入栈7个元素");
    ret=MinStackTop(&minstack,&top);
    printf("取栈顶元素:ret expect 1,actual %d,top expect a actual %c\n",ret,top);
    MinStackPop(&minstack);
    MinStackPop(&minstack);
    MinStackPop(&minstack);
    MinStackPop(&minstack);
    PrintMinStack(&minstack,"出栈4个元素");

    ret=MinStackTop(&minstack,&top);
    printf("取栈顶元素:ret expect 1,actual %d,top expect e actual %c\n",ret,top);
    MinStackDestroy(&minstack);
    printf("销毁后：size expect 0,actual %lu\n",minstack.date.size);
}
void TestMinStack_1()
{
    TEST_HEADER;
    SeqStack minstack;
    MinStackInit_1(&minstack);
    MinStackType top='\0';
    int ret=0;
    ret=MinStackTop_1(&minstack,&top);
    printf("尝试对空栈进行取栈顶元素:ret expect 0,actual %d\n",ret);
    MinStackPop_1(&minstack);
    PrintMinStack_1(&minstack,"尝试对空栈进行出栈");

    MinStackPop_1(&minstack);
    MinStackPush_1(&minstack,'g');
    MinStackPush_1(&minstack,'f');
    MinStackPush_1(&minstack,'e');
    MinStackPush_1(&minstack,'d');
    MinStackPush_1(&minstack,'c');
    MinStackPush_1(&minstack,'b');
    MinStackPush_1(&minstack,'a');
    PrintMinStack_1(&minstack,"入栈7个元素");
    ret=MinStackTop_1(&minstack,&top);
    printf("取栈顶元素:ret expect 1,actual %d,top expect a actual %c\n",ret,top);
    MinStackPop_1(&minstack);
    MinStackPop_1(&minstack);
    MinStackPop_1(&minstack);
    MinStackPop_1(&minstack);
    PrintMinStack_1(&minstack,"出栈4个元素");

    ret=MinStackTop_1(&minstack,&top);
    printf("取栈顶元素:ret expect 1,actual %d,top expect e actual %c\n",ret,top);
    MinStackDestroy_1(&minstack);
    printf("销毁后：size expect 0,actual %lu\n",minstack.size);

}
void TestQueueWithTwoStack()
{
    TEST_HEADER;
    Queue queue;
    QueueInit(&queue);
    int ret=0;
    QueueType top='\0';
    ret=QueueFront(&queue,&top);
    printf("尝试对空队列进行取队首元素:ret expect 1,actual %d\n",ret);
    QueuePop(&queue);
    PrintQueue(&queue,"尝试对空队列进行出对列");
    QueuePush(&queue,'a');
    QueuePush(&queue,'b');
    QueuePush(&queue,'c');
    QueuePush(&queue,'d');
    QueuePush(&queue,'e');
    QueuePush(&queue,'f');
    QueuePush(&queue,'g');
    PrintQueue(&queue,"入队列7个元素");
    ret=QueueFront(&queue,&top);
    printf("取队首元素:ret expect 1,actual %d,top expect a actual %c\n",ret,top);
    QueuePop(&queue);
    QueuePop(&queue);
    QueuePop(&queue);
    QueuePop(&queue);
    PrintQueue(&queue,"出队列4个元素");
    ret=QueueFront(&queue,&top);
    printf("取队首元素:ret expect 1,actual %d,top expect e actual %c\n",ret,top);
    QueueDestroy(&queue);
    printf("销毁后：size expect 0,actual %lu\n",queue.Spop.size);
}
void TestStackWithTwoQueue()
{
    TEST_HEADER;
    Stack stack;
    StackInit(&stack);
    int ret=0;
    StackType top='\0';
    ret=StackTop(&stack,&top);
    printf("尝试对空栈取栈顶元素：ret expect 1,actual %d\n",ret);
    StackPop(&stack);
    PrintStack(&stack,"尝试对空栈进行出栈");
    StackPush(&stack,'g');
    StackPush(&stack,'f');
    StackPush(&stack,'e');
    StackPush(&stack,'d');
    StackPush(&stack,'c');
    StackPush(&stack,'b');
    StackPush(&stack,'a');
    PrintStack(&stack,"入栈7个元素");
    ret=StackTop(&stack,&top);
    printf("取栈顶元素：ret expect 1,actual %d,top expect a,actual %c\n",ret,top);
    StackPop(&stack);
    StackPop(&stack);
    StackPop(&stack);
    StackPop(&stack);
    PrintStack(&stack,"出栈4个元素");
    ret=StackTop(&stack,&top);
    printf("取栈顶元素：ret expect 1,actual %d,top expect e,actual %c\n",ret,top);
    StackDestroy(&stack);
    printf("销毁后：size expect 0,actual %lu\n",stack.q1.size);
}
void TestShareStack()
{
    TEST_HEADER;
    ShareStack share;
    ShareStackInit(&share);
    int ret_1=0;
    int ret_2=0;
    ShareStackType tmp_1='\0';
    ShareStackType tmp_2='\0';
    ShareStackPush_1(&share,'g');
    ShareStackPush_1(&share,'f');
    ShareStackPush_1(&share,'e');
    ShareStackPush_1(&share,'d');
    ShareStackPush_1(&share,'c');
    ShareStackPush_1(&share,'b');
    ShareStackPush_1(&share,'a');
    PrintShareStack_1(&share,"对栈一进行入栈7个元素");
    ret_1=ShareStackTop_1(&share,&tmp_1);
    printf("对栈一进行取栈顶元素 ret_1 expect 1,actual %d,tmp_1 expect a actual %c\n",ret_1,tmp_1);
    ShareStackPop_1(&share);
    ShareStackPop_1(&share);
    ShareStackPop_1(&share);
    ShareStackPop_1(&share);
    PrintShareStack_1(&share,"对栈一进行出栈4个元素");
    ShareStackDestroy_1(&share);
    printf("销毁栈一后，top_1 expect 0,actual %lu\n",share.top1);
    ShareStackPush_2(&share,'g');
    ShareStackPush_2(&share,'f');
    ShareStackPush_2(&share,'e');
    ShareStackPush_2(&share,'d');
    ShareStackPush_2(&share,'c');
    ShareStackPush_2(&share,'b');
    ShareStackPush_2(&share,'a');
    PrintShareStack_2(&share,"对栈二进行入栈7个元素");
    ret_2=ShareStackTop_2(&share,&tmp_2);
    printf("对栈二进行取栈顶元素 ret_2 expect 1,actual %d,tmp_2 expect a actual %c\n",ret_2,tmp_2);
    ShareStackPop_2(&share);
    ShareStackPop_2(&share);
    ShareStackPop_2(&share);
    ShareStackPop_2(&share);
    PrintShareStack_2(&share,"对栈二进行出栈4个元素");
    ShareStackDestroy_2(&share);
    printf("销毁栈二后，top_2 expect %d,actual %lu\n",ShareStackSize-1,share.top2);
}
int main()
{
    TestIsStackOrder();
    TestMinStack();
    TestMinStack_1();
    TestQueueWithTwoStack();
    TestStackWithTwoQueue();
    TestShareStack();
    return 0;
}
